#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
const int N = 1e5 + 10;
int num[N], n, m,s[N];
void debug()
{
    cout << "debug" << endl;
}
struct pp
{
    int jie, sy;
} q[N];
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> num[i];
    }
    int maxx = 0;
    ll cnt = 1;
    ll t = n;
    while (t--)
    {
       
        vector<pair<int, int>> day(m + 1);
        for (int i = 1; i <= m; i++)
        {
            ll x, y;
            cin >> x >> y;
            num[cnt] = num[cnt] - x + y;
            s[cnt] += x;
        }
        //cout << num[cnt] << ":" << endl;
        maxx = max(maxx, s[cnt++]);
    }
    // debug();
    //cout << maxx << endl;
    for (int i = 1; i <= n; i++)
    {
        //debug();
        if (s[i] != maxx)
        {
            cout << num[i] << "\n";
        }
        else
        {
            cout << num[i] << "*" << endl;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
